package com.itheima.spring_mvc_xml.controller;

import com.itheima.spring_mvc_xml.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController2 {

    @RequestMapping("/sayhello")
    public ModelAndView show() {
        ModelAndView mv = new ModelAndView();
        mv.addObject("msg", "heima 125 is beat");
        mv.setViewName("hello");
        return mv;
    }

    @RequestMapping("show1")
    public String show1(Model model, User user) {

        model.addAttribute("msg", user);
        return "hello";
    }


    @RequestMapping(value = "/show2", method = RequestMethod.POST)
    @ResponseBody//加在方法上表示，把返回结果的json直接作为视图，在response响应体中返回
    public User show2(Model model, User user) {

        return user;
    }

    @RequestMapping(value = "/show3", method = RequestMethod.POST)
    @ResponseBody
    public User show3(Model model, @RequestBody User user) {
        //传入的user要是json格式
        return user;

    }
}
